/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.metadataRepository.repository.xmlConfiguration;

import cz.mzk.oai.metadataRepository.transformation.XsltConfig;
import cz.mzk.oai.metadataRepository.metadata.MetadataFormat;
import java.io.File;
import java.util.Set;

/**
 *
 * @author Martin Rehanek (rehan at mzk.cz)
 */
class CollectionConfig extends CollectionsCommonConfig {

    private final String name;
    private final File metadataDir;
    private final Set<Integer> setIds;
    private final String alephBase;
    private final boolean itemsCanBeMoved;

    CollectionConfig(String name, File metadataDir, Set<MetadataFormat> metadataFormats, Set<XsltConfig> xsltConfigs, Set<Integer> setIds, String alephBase, boolean itemsCanBeMoved) {
        super(metadataFormats, xsltConfigs);
        this.name = name;
        this.metadataDir = metadataDir;
        this.setIds = setIds;
        this.alephBase = alephBase;
        this.itemsCanBeMoved = itemsCanBeMoved;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the metadataDir
     */
    public File getMetadataDir() {
        return metadataDir;
    }

    /**
     * @return the setIds
     */
    public Set<Integer> getSetIds() {
        return setIds;
    }

    void includeMetadataFormats(CollectionsCommonConfig commonConfig) {
        for (MetadataFormat format : commonConfig.getMetadataFormats()) {
            metadataFormats.add(format);
        }
    }

    void includeTransformations(CollectionsCommonConfig commonConfig) {
        for (XsltConfig config : commonConfig.getTransformationConfigs()) {
            xsltConfigs.add(config);
        }
    }

    void addMetadataFormats(Set<MetadataFormat> metadataFormats) {
        for (MetadataFormat format : metadataFormats) {
            this.metadataFormats.add(format);
        }
    }

    void addTransformations(Set<XsltConfig> xsltConfigs) {
        for (XsltConfig config : xsltConfigs) {
            this.xsltConfigs.add(config);
        }
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        char eoln = '\n';
        result.append("name: ").append(name).append(eoln);
        result.append("metadataDir: ").append(metadataDir).append(eoln);
        result.append("formats: ");
        for (MetadataFormat format : metadataFormats) {
            result.append(format.toString()).append(',');
        }
        result.append(eoln);
        result.append("set ids: ");
        for (Integer id : setIds) {
            result.append(Integer.toString(id)).append(',');
        }
        result.append(eoln);
        result.append("aleph base: ").append(alephBase).append(eoln);
        result.append("transformations: ").append(eoln);
        for (XsltConfig xsltConfig : xsltConfigs) {
            XsltConfig trans = (XsltConfig) xsltConfig;
            result.append(trans.getFromFormat().toString());
            result.append("->");
            result.append(trans.getToFormat().toString());
            result.append(": ").append(trans.getXsltFile().getAbsolutePath());
            result.append(eoln);
        }
        return result.toString();
    }

    /**
     * @return the alephBase
     */
    public String getAlephBase() {
        return alephBase;
    }

    boolean itemsCanBeTransfered() {
        return itemsCanBeMoved;
    }
}
